package com.example.administrator.testxingpiao.ui.main.homepage;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.administrator.testxingpiao.R;
import com.example.administrator.testxingpiao.bean.ListBean;
import com.example.administrator.testxingpiao.ui.detail.TicketDetailActivity;

import java.util.List;

/**
 * Created by Administrator on 2016/8/4.
 */
public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.ItemViewHolder> {

    private List<ListBean> mList;
    private final LayoutInflater inflater;
    private Context context;

    public RecyclerAdapter(List<ListBean> list, Context context){
        this.mList = list;
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public ItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.item_recyclerview_homepage, null);
        return new ItemViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ItemViewHolder holder, final int position) {

        Glide.with(context).load(mList.get(position).getImage()).into(holder.ivItem);
        holder.ivItem.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, WebActivity.class);
                intent.putExtra("url",mList.get(position).getUrlWap());
                context.startActivity(intent);
            }
        });
        holder.tvTitle.setText(mList.get(position).getTitle());
        holder.tvPrice.setText(mList.get(position).getFtitle());
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    class ItemViewHolder extends RecyclerView.ViewHolder{
        private ImageView ivItem;
        private TextView tvTitle;
        private TextView tvPrice;

        public ItemViewHolder(View itemView) {
            super(itemView);
            ivItem = (ImageView) itemView.findViewById(R.id.imageview_item_recycler_homepage);
            tvTitle = (TextView) itemView.findViewById(R.id.textview_title_item_recycler_homepage);
            tvPrice = (TextView) itemView.findViewById(R.id.textview_price_item_recycler_homepage);
        }
    }
}
